<template>
	<div>
		<!-- :visible.sync="$store.state.mealflag" -->
		<el-dialog :close-on-click-modal="flag" :show-close="flag" title="套餐信息" :visible.sync="$store.state.majorMealflag" width="30%"
		 center>
			<span>
				<!-- ////////////////////// -->
				<el-form ref="form" label-width="80px">
					<el-form-item label="套餐名称">
						<el-input v-model="mealInfo.majormealremark" maxlength=15></el-input>
					</el-form-item>
					<el-form-item label="套餐价格">
						<el-input v-model="mealInfo.majormealmoney" maxlength=15 @keyup.native="trim()" style="width:40%"></el-input> 元
					</el-form-item>
					<el-form-item label="是否启用">
						<el-switch v-model="mealInfo.majormealstate"></el-switch>
					</el-form-item>
					<!-- 		  <el-form-item label="活动性质">
		    <el-checkbox-group v-model="mealInfo.mealtype">
		      <el-checkbox label="长期套餐" name=1></el-checkbox>
		      <el-checkbox label="短期套餐" name=2></el-checkbox>
		    </el-checkbox-group>
		  </el-form-item> -->
					<el-form-item label="套餐内容">
						<el-input type="textarea" v-model="mealInfo.majormealmsg" maxlength=55></el-input>
					</el-form-item>
				</el-form>
				<!-- ////////////////////// -->
			</span>
			<span slot="footer" class="dialog-footer">
				<el-button type="danger" @click="mealflag1(false)">删除</el-button>
				<el-button @click="mealflagcancel()">取 消</el-button>
				<el-button type="primary" @click="mealflag(false)">保存</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import {
		request
	} from "network/request.js"
	export default {
		props: {
			mealInfo: {
				"majormealid": 0,
				"majormealmoney": 0,
				"majormealmsg": "string",
				"majormealremark": "string",
				"majormealstate": "string"
			}
		},
		data() {
			return {
				lab1: 1,
				lab2: 2,
				flag: false,
				flag2: true,
				mealstate2:"1"
			};
		},
		methods: {
			mealflag(flag) {
				if(this.mealInfo.majormealstate==true){
					this.mealstate2="1";
				}else{
				this.mealstate2="0"
				}
				request({
					url: '/Meal/majorMeals',
					method: 'patch',
					data: {
						// id:this.$store.state.mealid
							"majormealid": this.mealInfo.majormealid,
							"majormealmoney": this.mealInfo.majormealmoney,
							"majormealmsg": this.mealInfo.majormealmsg,
							"majormealremark": this.mealInfo.majormealremark,
							"majormealstate": this.mealstate2
					}
				}).then(res => {
					console.log(this.mealstate2)
					
					this.$store.commit("updateMajorMeal", false)
					this.$store.commit("updateMajorMealid", 0)
					this.$router.push("blank_emt")
				})
			},
			mealflag1(flag) {
				/*提醒用户是否删除*/
				     this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
				          confirmButtonText: '确定',
				          cancelButtonText: '取消',
				          type: 'warning'
				        }).then(() => {
									/*****************/
									request({
										url: '/Meal/majorMeals',
										method: 'patch',
										data: {
											"majormealid": this.mealInfo.majormealid,
											"majormealmoney": this.mealInfo.majormealmoney,
											"majormealmsg": this.mealInfo.majormealmsg,
											"majormealremark": this.mealInfo.majormealremark,
											"majormealstate": 2
										}
									}).then(res => {
										// console.log(this.mealstate2)
										this.$store.commit("updateMajorMeal", false)
										this.$store.commit("updateMajorMealid", 0)
										this.$router.push("blank_emt")
									})
									
									/*****************/
				          this.$message({
				            type: 'success',
				            message: '删除成功!'
				          });
				        }).catch(() => {
				          this.$message({
				            type: 'info',
				            message: '已取消删除'
				          });          
				        });
				
				
				
				/*************************/
			
			},
			mealflagcancel() {
				this.$store.commit("updateMajorMeal", false)
				this.$store.commit("updateMajorMealid", 0)
			},
			onSubmit() {
				console.log('submit!');
			},
			trim() {
				this.mealInfo.majormealmoney = this.mealInfo.majormealmoney.replace(/[^0-9\.]/g, '')
				// console.log(this.form.name)
			}
		}
	};
</script>

<style>
</style>
